#include "time1c1.h"

DPOOL_txDIF_tstClkDpoolData DPOOL_txDIF_stClkDpoolData = {0,0,0};


/*time main function */
void time_vMain(void)
{
  static uint32 s_u32ElapsedMs = 0;
        uint16 g_CAN_Hour = Time_Hour_ReadFn();
        uint16 g_CAN_Minutes = Time_Minutes_ReadFn();
        uint16 g_CAN_TimeMod = TimeMod_ReadFn();
        if ((g_CAN_Hour < 0x18) &&
            (g_CAN_Minutes < 0x3C) &&
            (g_CAN_TimeMod <= 1))
        {
            stClockData.DIF_u16Hour = g_CAN_Hour;
            stClockData.DIF_u16Min = g_CAN_Minutes;
            stClockData.DIF_u16Mode = g_CAN_TimeMod;
            if (stClockData.DIF_u16Mode == 1) {
                if (stClockData.DIF_u16Hour == 0) {
                    stClockData.DIF_u16Hour = 12;
                }
            }
            s_u32ElapsedMs = 0;
        }
        else
        {
            s_u32ElapsedMs += 100U;
            if (s_u32ElapsedMs >= (60U * 1000U))
            {
                stClockData.DIF_u16Min++;
                if (stClockData.DIF_u16Min >= 60)
                {
                    stClockData.DIF_u16Min = 0;
                    stClockData.DIF_u16Hour++;
                    if (stClockData.DIF_u16Hour >= 24)
                    {
                        stClockData.DIF_u16Hour = 0;
                    }
                }
                s_u32ElapsedMs -= (60U * 1000U);
            }
        }
}
